<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="媒资名称" prop="mediaName">
            <el-input
                v-model="queryParams.mediaName"
                placeholder="请输入媒资名称"
                clearable
                style="width: 240px"
                @keyup.enter="handleQuery"
            />
          </el-form-item>
          <el-form-item label="媒资类型" prop="mediaTypeList">
            <el-select
                v-model="queryParams.mediaType"
                placeholder="媒资类型"
                clearable
                style="width: 240px"
            >
              <el-option
                  v-for="item in mediaTypeList"
                  :key="item.id"
                  :label="item.typeName"
                  :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" border :data="mediaSourceList" style="width: 100%">
          <el-table-column type="selection" :resizable="true" align="center"/>
          <el-table-column label="媒资名称" :resizable="true" align="center" key="mediaName" prop="mediaName" v-if="columns[0].visible"/>
          <el-table-column label="播放时长" :resizable="true" align="center" key="timeLength" prop="timeLength" v-if="columns[1].visible"
                           :show-overflow-tooltip="true"/>
          <el-table-column label="文件大小" :resizable="true" align="center" key="fileSize" prop="fileSize" v-if="columns[2].visible"
                           :show-overflow-tooltip="true"/>
          <el-table-column label="媒资类型" :resizable="true" align="center" key="mediaTypeName" prop="mediaTypeName"
                           v-if="columns[3].visible" :show-overflow-tooltip="true"/>
          <el-table-column label="访问级别" :resizable="true" align="center" key="accessLevel" prop="accessLevel"
                           v-if="columns[4].visible" width="120">
            <template #default="scope">
              <dict-tag :options="t_media_access_level" :value="scope.row.accessLevel"/>
            </template>
          </el-table-column>
          <el-table-column label="审核状态" align="center" prop="reviewStatus" v-if="columns[5].visible" :resizable="true">
            <template #default="scope">
              <dict-tag :options="t_review_status" :value="scope.row.reviewStatus"/>
            </template>
          </el-table-column>
          <el-table-column label="上传时间" align="center" prop="uploadTime" v-if="columns[6].visible" :resizable="true">
            <template #default="scope">
              <span>{{ parseTime(scope.row.uploadTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="文件试听" :resizable="false" width="300px;" align="center" prop="uploadTime" v-if="columns[6].visible">
            <template #default="scope">
              <VideoFlv :src="scope.row.fileName" :mediaType="'mp3'" controls="controls" style="width: 300px; height: 30px;"></VideoFlv>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
            <template #default="scope">
              <el-tooltip content="审核通过" placement="top" v-if="scope.row.userId !== 1">
                <el-button link type="primary" icon="Select" @click="pass(scope.row)"
                           v-hasPermi="['media:mediaReview:auditActions']"></el-button>
              </el-tooltip>
              <el-tooltip content="审核不通过" placement="top" v-if="scope.row.userId !== 1">
                <el-button link type="primary" icon="CloseBold" @click="failed(scope.row)"
                           v-hasPermi="['media:mediaReview:auditActions']"></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <pagination
            v-show="total > 0"
            :total="total"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            @pagination="getList"
        />
      </el-col>
    </el-row>

  </div>
</template>

<script setup name="MediaReview">
import {
  listMediaSource,
  auditActions
} from "@/api/system/mediaReview";
import {
  getMediaTypeAll
} from "@/api/system/mediaType";

const {proxy} = getCurrentInstance();
const {
  t_media_access_level,
  t_review_status,
  t_media_file_type
} = proxy.useDict("t_media_access_level", "t_review_status", "t_media_file_type");

const mediaSourceList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const mediaTypeList = ref([]);

// 列显隐信息
const columns = ref([
  {key: 0, label: `媒资名称`, visible: true},
  {key: 1, label: `播放时长`, visible: true},
  {key: 2, label: `文件大小`, visible: true},
  {key: 3, label: `媒资类型`, visible: true},
  {key: 4, label: `访问级别`, visible: true},
  {key: 5, label: `审核状态`, visible: true},
  {key: 6, label: `上传时间`, visible: true}
]);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    mediaName: undefined,
    mediaType: undefined,
    reviewStatus: 0
  }
});

const {queryParams} = toRefs(data);


/** 查询用户列表 */
function getList() {
  loading.value = true;
  listMediaSource(queryParams.value).then(res => {
    loading.value = false;
    mediaSourceList.value = res.rows;
    total.value = res.total;
  });
  getMediaTypeAll().then(res => {
    mediaTypeList.value = res.data;
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  queryParams.value.regionId = undefined;
  handleQuery();
}

async function pass(row){
  row.reviewStatus = 1;
  await auditActions(row).then(res=>{
    if(res.code=== 200){
      proxy.$modal.msgSuccess(res.msg  + " 审核成功" + row.mediaName);
    }else{
      proxy.$modal.msgError(res.msg  + " 审核失败" + row.mediaName);
    }
  })
  getList();
}

async function failed(row) {
  row.reviewStatus = 2;
  await auditActions(row).then(res=>{
    if(res.code=== 200){
      proxy.$modal.msgSuccess(res.msg  + " 审核成功" + row.mediaName);
    }else{
      proxy.$modal.msgError(res.msg  + " 审核失败" + row.mediaName);
    }
  })
  getList();
}

getList();
</script>
